package com.jiyun.common.vo;

import lombok.Data;
import lombok.ToString;

/**
 * @projectName: day03_parent_p11
 * @package: com.jiyun.vo
 * @className: R
 * @author: 耿嘉军
 * @date: 2023/7/27 16:08
 * @version: 1.0
 */
@Data
@ToString
public class R<T> {
    /**
     * 标志变量  1： 成功
     *          2： 失败
     */
    private String code;
    /**
     * 返回的消息
     */
    private String message;
	  /**
     * 结果是true/false
     */
    private boolean success;
    /**
     * 返回的数据
     */
    private T data;

    public static R<Object> ok(Object data){
        R<Object> objectR = new R<Object>();
        objectR.setCode("1");
        objectR.setMessage("成功");
        objectR.setSuccess(true);
        objectR.setData(data);
        return objectR;
    }

    public static R error(){
        R<Object> objectR = new R<Object>();
        objectR.setCode("2");
        objectR.setSuccess(false);
        objectR.setMessage("失败");
        return objectR;
    }

    public static R message(String message){
        R<Object> objectR = new R<>();
        objectR.setMessage(message);
        return objectR;
    }

    public static R code(String code){
        R<Object> objectR = new R<>();
        objectR.setCode(code);
        return objectR;
    }
}
